package com.example.house.web.controller;


import com.example.house.common.bean.Identify;
import com.example.house.common.bean.Result;
import com.example.house.common.config.redis.RedisOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zengyz
 * @date 2018-01-01
 */
@RestController
public class AuthenticationController {

    @Autowired
    private RedisOperation redisOperation;

    @RequestMapping(value = "/identify",method = RequestMethod.POST)
    public Result identify(@RequestBody Identify identify){
        if (null!=identify&& StringUtils.isNotEmpty(identify.getToken())&&StringUtils.isNotEmpty(identify.getIp())){
            Object obj = redisOperation.get(identify.getIp() + "--" + identify.getToken());
            if (null==obj){
                return Result.error(300,"用户未登陆，请重新登陆以后在操作");
            }
            return Result.ok("权限鉴定通过");
        }else{
            return Result.error(300,"用户非法登陆");
        }
    }
}
